<?php
namespace Admin\Service;

use Think\Service\BasicService;

class YZGoodsService extends BasicService {
    public function insert($model) {
        return $this->db->add($model);
    }

    public function remove($condition) {
        return $this->db->where($condition)->delete();
    }

    public function update($where,$model =array()) {
        return $this->db->where($where)->save($model);
    }

    public function find($condition) {
        return $this->db->find($condition);
    }

    public function query($condition,$order ='created_time desc',$limit = array(),$field=null) {
        $data = $this->db->field($field)
            ->where($condition)->limit($limit['start'],$limit['end'])
            ->order($order)->select();
        return $data;
    }

    public function getcount($condition){
        $data = $this->db->where($condition)->count();;
        return $data;
    }

    public function erp_update_yz_goods_query($condition) {
        $data = $this->db->where($condition)->select();
        return $data;
    }

    public function AddAll($model,$where) {
        $this->db->startTrans();
        $DELOK = $this->db->where($where)->delete();
        $HALOK = $this->db->where($where)->select();
        if ($DELOK || !$HALOK) {
            foreach ($model as $k => $v) {
                $temp =  array();
                foreach ($v as $k1 => $v1){
                    $temp[$k1]['mallid'] = $where['mallid'];
                    $temp[$k1]['created_time'] = $v1['created_time'];
                    $temp[$k1]['detail_url'] = $v1['detail_url'];
                    $temp[$k1]['quantity'] = 1000;
                    $temp[$k1]['post_fee'] = $v1['post_fee'];
                    $temp[$k1]['item_id'] = $v1['item_id'];
                    $temp[$k1]['item_type'] = $v1['item_type'];
                    $temp[$k1]['title'] = $v1['title'];
                    $temp[$k1]['item_no'] =$v1['item_no'];
                    $temp[$k1]['update_time'] = $v1['update_time'];
                    $temp[$k1]['price'] = $v1['price'];
                    $temp[$k1]['alias'] = $v1['alias'];
                    $temp[$k1]['post_type'] = $v1['post_type'];
                }
                $ADDOK = $this->db->addAll($temp);
                if (!$ADDOK) {
                    $this->db->rollback();
                    return 0;
                }
            }
            $this->db->commit();
            return 1;

        } else {
            $this->db->rollback();
            return 0;
        }
    }

    public function AddAll_new($model) {
        $this->db->startTrans();
        $DELOK = $this->db->where('1')->delete();
        if ($DELOK) {
            $ADDOK = $this->db->addAll($model);
            if ($ADDOK) {
                $this->db->commit();
                return 1;
            }

        }
        $this->db->rollback();
        return 0;
    }



}

?>